<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Admin extends MY_Admin
{
	/**
	 * Constructor
	 *
	 * @access	public
	 */
	function Admin()
	{
		parent::MY_Admin();
		
		// Template Settings
		$this->template->metas('title', 'Administration Backend');
                $this->load->helper('form');
	}

	// --------------------------------------------------------------------
	
	/**
	 * Controller Default Function
	 *
	 * @access	public
	 */
	function index()
	{		
		$data['new_version'] = $this->_get_latest();
				
		$this->template->display('admin/main', $data);
	}
	
	// --------------------------------------------------------------------
	
	/**
	 * Get the latest version of the application
	 *
	 * Grabs the Assembla version document, reads out the version number and
	 * returns the version if it's newer.
	 *
	 * @access	private
	 * @return	mixed	new version or false
	 * @see		http://www.assembla.com/wiki/show/breakoutdocs/Document_REST_API
	 */
	function _get_latest()
	{
		// Connection options
		$params = array(
		 				'http'	=>	array('timeout'	=>	1)
						);

		// Create stream context and open the stream
		// @TODO: Put the file version url in a config variable
		$context = stream_context_create($params);		
		$latest = @file_get_contents("http://www.assembla.com/file/linkster/1_version.txt", 0, $context);
		
		if ($latest)
		{
			return (version_compare(APP_VERSION, $latest) == -1) ? $latest : 'You have the latest version.';
		}

		return 'Cannot establish connection.';
	}
}

/* End of file admin.php */
/* Location: ./application/controllers/admin/admin.php */